package tests;

import common.Utils;
import org.openqa.selenium.By;

import java.io.IOException;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User:DELL
 * Date:2025-03-30
 * Time:22:54
 */
public class ForumLisePage extends Utils {
    public static String url="http://127.0.0.1:9580/index.html";
    public ForumLisePage() {
        super(url);
    }
    //查看元素是否存在
    public void ListPageRight() throws IOException, InterruptedException {
        //查看元素是否存在
        driver.findElement(By.cssSelector("body > div.page > header.navbar.navbar-expand-md.navbar-light.d-print-none > div > h1"));
        //发布帖子
        driver.findElement(By.cssSelector("#bit-forum-content > div.page-header.d-print-none > div > div > div.col-auto.ms-auto.d-print-none > div > a.btn.btn-primary.d-none.d-sm-inline-block.article_post"));
        //用户头像
        driver.findElement(By.cssSelector("#index_nav_avatar"));
        //搜索框
        driver.findElement(By.cssSelector("body > div.page > header.navbar.navbar-expand-md.navbar-light.d-print-none > div > div > div.nav-item.d-none.d-md-flex.me-3 > div > form > div > input"));
        //夜间模式
        driver.findElement(By.cssSelector("body > div.page > header.navbar.navbar-expand-md.navbar-light.d-print-none > div > div > div:nth-child(2) > a.nav-link.px-0.hide-theme-dark"));
        //私信
        driver.findElement(By.cssSelector("body > div.page > header.navbar.navbar-expand-md.navbar-light.d-print-none > div > div > div:nth-child(2) > div > a"));
        //分页元素
        driver.findElement(By.cssSelector("#topBoardList > li:nth-child(2) > a > span.nav-link-title"));
        Thread.sleep(3000);
        getScreenShot(getClass().getName());
        Thread.sleep(3000);
    }
    //点击发布帖子，会进入其页面,并进行发布
    public void publish() throws InterruptedException, IOException {
        //点击发布帖子
        driver.findElement(By.cssSelector("#bit-forum-content > div.page-header.d-print-none > div > div > div.col-auto.ms-auto.d-print-none > div > a.btn.btn-primary.d-none.d-sm-inline-block.article_post")).click();
        //判断是否进入相应的页面
        String text=driver.findElement(By.cssSelector("#bit-forum-content > div.page-header.d-print-none > div > div > div > h2")).getText();
        String expect="发新帖";
        Thread.sleep(3000);
        driver.findElement(By.cssSelector("#article_post_title")).sendKeys("你好！");
        Thread.sleep(3000);
        driver.findElement(By.cssSelector("#edit-article > div.CodeMirror.cm-s-default.CodeMirror-wrap.CodeMirror-empty > div.CodeMirror-scroll > div.CodeMirror-sizer > div > div > div > div.CodeMirror-code > div > pre")).sendKeys("你好你好你好");
        Thread.sleep(3000);
        driver.findElement(By.cssSelector("#article_post_submit")).click();
        Thread.sleep(3000);
        //检查是否发布成功
        String text1=driver.findElement(By.cssSelector("#artical-items-body > div:nth-child(1) > div > div.col > div.text-truncate")).getText();
        String expect2="你好！";
        assert expect2.equals(text1);
        driver.quit();
    }
}
